package com.zj.project.activity

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.zj.project.BR
import com.zj.project.R
import com.zj.project.common.base.BaseActivity
import com.zj.project.common.base.BasePagingAdapter
import com.zj.project.databinding.ActivityPagingBinding
import com.zj.project.viewmodel.PagingViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

class PagingActivity : BaseActivity<ActivityPagingBinding, PagingViewModel>() {
    override fun layoutId(): Int {
        return R.layout.activity_paging
    }

    override fun initData(savedInstanceState: Bundle?) {
        val basePagingAdapter = BasePagingAdapter()
        binding.apply {
            pagingRecycler.adapter = basePagingAdapter
        }

        lifecycleScope.launch {
            viewModel.getData().collectLatest {
                basePagingAdapter.submitData(it)
            }
        }


    }

    override fun variableId(): Int {
        return BR.paging
    }
}